home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / SCRNSAVE.BAT < prev    next >
DOS Batch File  |  1994-03-04  |  2KB  |  70 lines

  1. @echo off
  2. REM *****************************************************
  3. REM *** ScrnSave.bat - Save screen contents to a file ***
  4. REM *** ver.1                                         ***
  5. REM *****************************************************
  6.  
  7. CEnvi %0.bat %1 %2
  8. GOTO CENVI_EXIT
  9.  
  10. #include <Screen.lib>
  11.  
  12. ScrHeight = ScreenSize().row;
  13. ScrWidth = ScreenSize().col;
  14.  
  15. main(argc,argv)
  16. {
  17.    if ( argc != 2  ||  !strcmpi(argv[1],"/?")  ||  !strcmpi(argv[1],"/help") )
  18.       Instructions();
  19.    else
  20.       CaptureScreen(argv[1]);
  21. }
  22.  
  23. Instructions()
  24. {
  25.    printf("\a\n")
  26.    printf("ScrnSave - Save current ASCII screen to a file\n")
  27.    printf("\n")
  28.    printf("SYNTAX: ScrnSave <FileSpec>\n")
  29.    printf("\n")
  30.    printf("Where: FileSpec - Name of a file to capture screen to; if file then screen is\n")
  31.    printf("                  appended to current file, else file is created\n")
  32.    printf("\n")
  33.    printf("\n")
  34.    printf("Example: SCRNSAVE SCR.TXT\n")
  35.    printf("\n")
  36. }
  37.  
  38. CaptureScreen(FileSpec) // write screen to file
  39. {
  40.    if ( !(fp = fopen(FileSpec,"at")) ) {
  41.       printf("\aUnable to open file \"%s\" for appending.\n",FileSpec);
  42.       abort();
  43.    }
  44.  
  45.    GetCursor(SaveCursorRow,SaveCursorCol); // save cursor pos
  46.    for ( row = 0; row < ScrHeight; row++ ) {
  47.       buf = ReadScreenRow(row);
  48.       fprintf(fp,"%s\n",buf);
  49.    }
  50.    SetCursor(SaveCursorRow,SaveCursorCol); // restore cursor pos
  51.    fclose(fp);
  52. }
  53.  
  54. ReadScreenRow(row) // read this row to a buffer, turn 0 to blank and
  55. {                  // shorten string to last non-whitespace character
  56.    LastNonWhitespace = -1;
  57.    for ( col = 0; col < ScrWidth; col++ ) {
  58.       if ( !(c = ReadCharacter(row,col)) )
  59.          c = ' ';
  60.       else if ( !isspace(c) )
  61.          LastNonWhitespace = col;
  62.       buf[col] = c;
  63.    }
  64.    // terminate string beyond last nonwhitespace character
  65.    buf[LastNonWhitespace+1] = 0;
  66.    return(buf);
  67. }
  68.  
  69. :CENVI_EXIT
  70.